<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .head {
            position: relative;
            height: 50px;
            width: 500px;
            background-color: pink;
            margin: 0 auto;
        }
        
        .box {
            position: absolute;
            top: 0;
            right: -20px;
            height: 20px;
            width: 20px;
            background-color: purple;
            line-height: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="head">
        <div class="box">x</div>
    </div>
    <script>
        var box = document.querySelector(".box");
        var head = document.querySelector(".head");
        box.onclick = function() {
            head.style.display = "none";
        }
    </script>
</body>

</html>